local skel = fk.CreateSkill {
  name = "emo__fujian",
  tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["emo__fujian"] = "伏间",
  [":emo__fujian"] = "锁定技，游戏开始时，你令一名其他角色获得“敌”标记：其手牌始终对你可见，且你对其使用【杀】无距离限制。",

  ["@@emo__fujian_tar"] = "敌",
  ["#emo__fujian-choose"] = "伏间：令一名其色获得“敌”：其手牌对你可见，你对其用【杀】无距离限制",

  ["$emo__fujian1"] = "紫电耀魍魉之遁形，青霜斩魑魅之神魄。",
  ["$emo__fujian2"] = "纵汝亡命天涯海角，吾亦逐之负首而还。",
}

skel:addEffect(fk.GameStart, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = room:getOtherPlayers(player, false)
    if #targets == 0 then return false end
    local tos = #targets == 1 and targets or
    room:askToChoosePlayers(player, {
      targets = targets, min_num = 1, max_num = 1, skill_name = self.name, cancelable = false,
      prompt = "#emo__fujian-choose",
    })
    event:setCostData(self, {tos = tos})
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:addPlayerMark(to, "@@emo__fujian_tar")
    room:addTableMark(player, "emo__fujian_record", to.id)
  end,
})

skel:addEffect("visibility", {
  card_visible = function (self, player, card)
    if player:hasSkill(skel.name) then
      local mark = player:getTableMark("emo__fujian_record")
      local owner = Fk:currentRoom():getCardOwner(card)
      if owner and table.contains(mark, owner.id) then
        return true
      end
    end
  end,
})

skel:addEffect("targetmod", {
  bypass_distances = function(self, player, skill, card, to)
    return player and to and table.contains(player:getTableMark("emo__fujian_record"), to.id)
    and skill and skill.trueName == "slash_skill"
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  for _, pid in ipairs(player:getTableMark("emo__fujian_record")) do
    local to = player.room:getPlayerById(pid)
    player.room:removePlayerMark(to, "@@emo__fujian_tar")
  end
  player.room:setPlayerMark(player, "emo__fujian_record", 0)
end)

return skel
